<?php

//******************************* FUNCTION FOR PRINT ANY VALUE ***********************//
       
	   function PrintFunction($printVar)
	     {
		    echo $printVar;
		 }

//******************************** END OF THE CODE ***********************************//


//******************************* FUNCTION FOR DATABSE QUERY AND RELETED COMMON WORKS **************************//
   
     function Query($query)
       {
	     $db_query = mysql_query($query) or die(mysql_error());
		 return $db_query;
	   }
    
	function NumRows($query)
	  {
	     $num = mysql_num_rows($query);
		 return $num;
	  }
	 
	function FetchArray($query)
	  {
	     $Array = mysql_fetch_array($query);
		 return $Array;
	  }  

//********************************** END OF THE CODE *********************************//



//****************************** FUNCTION FOR REDIRECTION/ALERT FOR PAGE **************************//

    function RedirectPage($pageName)
     {
	    echo '<script>window.location="'.$pageName.'"</script>';
	 }
	 
	function Alert($topic) 
      {
	     echo '<script>alert("'.$topic.'");</script>';
	  }

//*********************************** END OF THE CODE ***********************************//



//************************************ FUNCTION FOR CALCULATING USER DETAILS FOR ADMIN ****************************//

	function calculate_user($prefix, $val)
	{
		if($val !="")
		{
			$db_user =Query("SELECT * from  ".$prefix."user WHERE status='".$val."'");
		}
		else
		{
			$db_user =Query("SELECT * from  ".$prefix."user");
		}
		$num_user = mysql_num_rows($db_user);
		echo $num_user;
	}

//******************************************** END OF THE CODE ************************************************//



//************************************** FUNCTION FOR IMAGE UPLOAD *******************************************//

function image_upload($temp_file,$old_file,$fileName,$folderName,$destination,$primarykeyValue,$nameOfFile,$fileSize,$mode,$nature)
   {
	    $exp = explode(".",$fileName);
		
//------------ CREATION OF FOLDER AUTOMATICALLY -----------------//
	
		if(!is_dir($folderName))
		{
			umask(0);
			mkdir($folderName,0777);
		}
		
		if($destination != "")
		{
			if(!is_dir($destination))
			{
				umask(0);
				mkdir($destination,0777);
			}
	   }
   
 //--------------------- END OF THE CODE ------------------------// 
 
 //------------------------- CODE FOR IMAGE UPLOADING -----------------------------// 
	
	if($exp[1] == 'jpg' || $exp[1] == 'bmp' || $exp[1] == 'gif' || $exp[1] == 'jpeg' || $exp[1] == 'png')
	 {
		 
		if($old_file == "") 
		 {
			$image = $nameOfFile.$primarykeyValue.".".$exp[1];
			$path = $folderName.$image;
			
			if($nature == "movieImage")
			  $image_upload = "UPDATE ".VIDEODETAILS." SET image='".$image."' WHERE movieID='".$primarykeyValue."'"; 
			if($nature == "shopImage")  
			  $image_upload = "UPDATE ".SHOP." SET shopImage='".$image."' WHERE shopID='".$primarykeyValue."'"; 
			  
			Query($image_upload);
			move_uploaded_file($temp_file,$path) or die("Upload Failed");
			$ht = 100;
			watermark($folderName,$destination,$image,$ht);
		}
	   else
	    {
			unlink($folderName.$old_file);
			
			$image = "VideoImage_new".$primarykeyValue.".".$exp[1];
			$path = $folderName.$image;
			
			if($nature == "movieImage")
			  $image_upload = "UPDATE ".VIDEODETAILS." SET image='".$image."' WHERE movieID='".$primarykeyValue."'"; 
			if($nature == "shopImage")  
			  $image_upload = "UPDATE ".SHOP." SET shopImage='".$image."' WHERE shopID='".$primarykeyValue."'"; 

			Query($image_upload);
			move_uploaded_file($temp_file,$path) or die("Upload Failed");
			$ht = 100;
			watermark($folderName,$destination,$image,$ht);
		}	
	 }
	 
//--------------------------- END OF THE CODE -------------------------------------------//

//---------------------------- CODE FOR MOVIE UPLOADING ---------------------------------//	 
	 
  elseif($exp[1] == 'mpg' || $exp[1] == 'mpeg' || $exp[1] == 'avi' || $exp[1] == 'dat' || $exp[1] == 'mov' || $exp[1] == 'wmv')
    {
	if($old_file == "") 
	  {
	   
	  //-------------------------------------- CODE FOR FLV CONVERSION ----------------------------------------------// 

		 ini_set( "max_execution_time", "3600" ); // sets the maximum execution time of this script to 1 hour.
		//$fileName = $_FILES['video']['name']; // get client side file name
		
		if( $fileName ) { 
			// Check File Type
			$fileNameParts = explode( ".", $fileName ); // seperate the name from the ext
			$fileExtension = end( $fileNameParts ); // part behind last dot
			$fileExtension = strtolower( $fileExtension ); // reduce to lower case
		
			if( !$fileExtension == "mpg" && !$fileExtension == "avi" && !$fileExtension == "mpeg" && !$fileExtension == "wmv" && !$fileExtension == "rm" && !$fileExtension == "dat" && !$fileExtension == "mov") {
				die( "Invalid Video Format." );
			}
			// Check File Size
			//$fileSize = $_FILES['video']['size']; // size of uploaded file
			if( $fileSize == 0 ) {
		
				die( "Sorry. The upload of $fileName has failed. The file size is 0." );
			} else if( $fileSize > 10240000 ) { //10 MB
				die( "Sorry. The file $fileName is larger than 10MB. Advice: reduce the file quality and upload again." );
		
			} else {
				$uploadDir = $folderName; // Where the temp file will go
				$uploadFile =$uploadDir.$fileName ; // Get rid of spaces in the filename
		
				$finalDir = $destination; // Where the final file will go
				$video = $nameOfFile.$primarykeyValue. ".flv";
				$finalFile = str_replace( " ", "",  $finalDir . $video ); // Get rid of spaces in the filename
		
				if ( !move_uploaded_file( $temp_file, $uploadFile ) ) {
					echo "Possible file upload attack!  Here's some debugging info:\n";
					echo( $_FILES );
				}
		
		
				$encode_cmd = "/usr/bin/ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
				exec( $encode_cmd );
				
				if($mode == 3) 
				   $update = "UPDATE ".VIDEODETAILS." SET video='".$video."' WHERE movieID='".$primarykeyValue."'"; 
				if($mode == 2) 
				   $update = "UPDATE ".VIDEODETAILS." SET trailer='".$video."' WHERE movieID='".$primarykeyValue."'"; 
				      
				Query($update);
				unlink( $uploadFile );
				chmod( $finalFile, 0644 );
					}
				}
	       //------------------------------------------ END OF THE CODE ------------------------------------------------------// 
			}
		else 
		  {
			 unlink($destination.$old_file);
		  
	  //-------------------------------------- CODE FOR FLV CONVERSION ----------------------------------------------//
	  
		 ini_set( "max_execution_time", "3600" ); // sets the maximum execution time of this script to 1 hour.
		//$fileName = $_FILES['video']['name']; // get client side file name
		
		if( $fileName ) { 
			// Check File Type
			$fileNameParts = explode( ".", $fileName ); // seperate the name from the ext
			$fileExtension = end( $fileNameParts ); // part behind last dot
			$fileExtension = strtolower( $fileExtension ); // reduce to lower case
		
			if( !$fileExtension == "mpg" && !$fileExtension == "avi" && !$fileExtension == "mpeg" && !$fileExtension == "wmv" && !$fileExtension == "rm" && !$fileExtension == "dat" && !$fileExtension == "mov") {
				die( "Invalid Video Format." );
			}
			// Check File Size
			//$fileSize = $_FILES['video']['size']; // size of uploaded file
			if( $fileSize == 0 ) {
		
				die( "Sorry. The upload of $fileName has failed. The file size is 0." );
			} else if( $fileSize > 10240000 ) { //10 MB
				die( "Sorry. The file $fileName is larger than 10MB. Advice: reduce the file quality and upload again." );
		
			} else {
				$uploadDir = $folderName; // Where the temp file will go
				$uploadFile =$uploadDir.$fileName ; // Get rid of spaces in the filename
		
				$finalDir = $destination; // Where the final file will go
				$video = $nameOfFile.$primarykeyValue. ".flv";
				$finalFile = str_replace( " ", "",  $finalDir . $video ); // Get rid of spaces in the filename
		
				if ( !move_uploaded_file( $temp_file, $uploadFile ) ) {
					echo "Possible file upload attack!  Here's some debugging info:\n";
					echo( $_FILES );
				}
		
		
				$encode_cmd = "/usr/bin/ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
				exec( $encode_cmd );
				
				if($mode == 3) 
				   $update = "UPDATE ".VIDEODETAILS." SET video='".$video."' WHERE movieID='".$primarykeyValue."'"; 
				if($mode == 2) 
				   $update = "UPDATE ".VIDEODETAILS." SET trailer='".$video."' WHERE movieID='".$primarykeyValue."'"; 
				   
				Query($update);
				unlink( $uploadFile );
				chmod( $finalFile, 0644 );
					}
				}
	       //------------------------------------------ END OF THE CODE ------------------------------------------------------// 
		  }	
	} 
//------------------------------------------ END OF THE CODE ------------------------------------------//	
  else
   {
      $topic = "Uploaded File Is Not In Proper Extension";
      Alert($topic);
   }	
}

//**************************************** END OF THE CODE ***************************************************//



//******************************************** FUNCTION FOR LOGIN ******************************************//

	function login($username,$password)
	{
		$select_login = "SELECT * FROM ".USER." WHERE username='".$username."' AND password='".$password."'";
		$mysql_query_login = Query($select_login);
		   
		   if($fetch_query_login = FetchArray($mysql_query_login))
			 {
				session_register("username");
				session_register("password"); 
				
				$_SESSION['username']=$fetch_query_login['username'];
				$_SESSION['userId']=$fetch_query_login['userId'];
				
			    $pageName = "main.php?opt=1";
			 }
		  else
			 {
			   $pageName = "userLogin.php?notlogin=true";
			 } 
		   RedirectPage($pageName);	 
	  }

//**************************************** END OF THE CODE ******************************************//



//***************************************** FUNCTION FOR LOGOUT ***************************************//
  
   function Logout()
    {
	   session_unset();
       $pageName = "index.php";
	   RedirectPage($pageName);	 
	}

//****************************************** END OF THE CODE *******************************************//



//*************************************** FUNCTION TO DO THE REGISTRATION ******************************//
    
	  function Registration($username,$password,$email,$fname,$lname,$address,$phone,$fax,$city,$zip)
	     {
		 //------------------------------- TO GET USERNAME AND MAIL FOR CHECKING DUPLICATE------------------------//
		 
				$select_user = "SELECT * FROM ".USER." WHERE username='".$username."'";
				$mysql_select_user = Query($select_user);
				$select_user_num = NumRows($mysql_select_user);
				
				$select_mailid = "SELECT * FROM ".USER." WHERE email='".$email."'";
				$mysql_select_mailid = Query($select_mailid);
				$num_mailid_row = NumRows($mysql_select_mailid);
			   
	 //-------------------------------------- SET THE FLAGS --------------------------------//
	 
			   if($select_user_num > 0)
				 $userFlag = 1;
			   else
				$userFlag = 0;	
			   
			   if($num_mailid_row > 0)
				 $mailFlag = 1;
			   else
				 $mailFlag = 0;
				 
   //---------------------------------------- END OF THE CODE -----------------------------//
   
			  if($mailFlag == 1 && $userFlag == 1)
				{
				  $topic = "same username and emailid exists,enter another";
				  Alert($topic);
				} 	 
			  elseif($mailFlag == 0 && $userFlag == 1)
				{
				  $topic = "same username exists,enter another one";
				  Alert($topic);
				}
			  elseif($mailFlag == 1 && $userFlag == 0)
				{
				  $topic = "same emailid exists,enter another one";
				  Alert($topic);
				}
				
   //------------------------------------- END OF THE CODE ---------------------------------------------------//	  			 
				 
			  else
				{
				  $inser_query_user="INSERT INTO ".USER." SET username='".$username."', password='".$password."',															firstName='".$fname."', lastName='".$lname."', email='".$email."',	address='".$address."',	phone='".$phone."', fax='".$fax."',	city='".$city."', zip='".$zip."', date='".$today."', status='u'";
															
			     $mysql_insert_query = Query($inser_query_user);											
			     $id = mysql_insert_id(); 
				 $pageName = "display.php?opt=1";
			     RedirectPage($pageName);	 
			}
		 }


//******************************************* END OF THE CODE ******************************************//

//**************************************** FUNCTION FOR ANY KIND INSERT *********************************//

       function InsertIntoDB($tableName,$fields)
          {
             $reqFieldArray = explode(",",$fields);
		     $arrayElement = count($reqFieldArray);
			 
			 if($tableName == "movie")
			   {
			      $check_org_title = "SELECT * FROM ".MOVIE." WHERE org_title='".$reqFieldArray[0]."'";
				  $check_org_title_query = Query($check_org_title);
				  $check_org_title_no = NumRows($check_org_title_query);
				  
				  if($check_org_title_no > 0)
				   {
				     $topic = "Please Choose Anather Title As Qriginal";
					 Alert($topic);
				   }
				  else
				   {
						$insert = "INSERT INTO ".MOVIE." SET org_title='".$reqFieldArray[0]."', title='".$reqFieldArray[1]."', director='".$reqFieldArray[2]."', producer='".$reqFieldArray[3]."', year='".$reqFieldArray[4]."', cast='".$reqFieldArray[5]."', description='".$reqFieldArray[6]."', cost='".$reqFieldArray[8]."', categoryId='".$reqFieldArray[8]."',shopID='".$reqFieldArray[9]."',uploaded_date='".$today."' , status='u'";
						Query($insert);
						$id = mysql_insert_id();
						
						$anather_insert = "INSERT INTO ".VIDEODETAILS." SET movieID='".$id."'";
						Query($anather_insert);
				   } 
			   }
			   
			 if($tableName == "shop")
			   {
			      $check_org_title = "SELECT * FROM ".SHOP." WHERE shopName='".$reqFieldArray[0]."'";
				  $check_org_title_query = Query($check_org_title);
				  $check_org_title_no = NumRows($check_org_title_query);
				  
				  if($check_org_title_no > 0)
				   {
				     $topic = "Please Choose Anather Title As Qriginal";
					 Alert($topic);
				   }
				  else
				   {
						$insert = "INSERT INTO ".SHOP." SET shopName='".$reqFieldArray[0]."', cdate='".$today."', status='U'";
						Query($insert);
						$id = mysql_insert_id();
				   } 
			   }
			 return $id;  
		  }

//*********************************************** END OF THE CODE **************************************//


//**************************************** FUNCTION FOR ANY TYPE OF UPDATE ********************************//

        function UpdateToDb($tableName,$fields,$primarykeyValue)
		  {
             $reqFieldArray = explode(",",$fields);
		     $arrayElement = count($reqFieldArray);
			  
			  if($tableName == "movie")
		        {
					$update = "UPDATE ".MOVIE." SET org_title='".$reqFieldArray[0]."', title='".$reqFieldArray[1]."', director='".$reqFieldArray[2]."', producer='".$reqFieldArray[3]."', year='".$reqFieldArray[4]."', cast='".$reqFieldArray[5]."', description='".$reqFieldArray[6]."', cost='".$reqFieldArray[7]."', categoryId='".$reqFieldArray[8]."',shopID='".$reqFieldArray[9]."',uploaded_date='".$today."' , status='u' WHERE movieId='".$primarykeyValue."'";
					Query($update);
				}
				
		      if($tableName == "shop")
			   {
					$update = "UPDATE ".SHOP." SET shopName='".$reqFieldArray[0]."' WHERE shopID='".$primarykeyValue."'";
					Query($update);
			   }
		  }

//******************************************** END OF THE CODE *********************************************//



//******************************** FUNCTION FOR SHOW DETAILS **************************************//
         
	    function showDetails($type,$primaryKeyValue)
		 {
            if($type == 'video')
			 {
                $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID and aa.movieId='".$primaryKeyValue."'";
				$video_query = Query($video);
				$video_array = FetchArray($video_query);
				
			    $video = $video_array['video'];
				$trailer = $video_array['trailer'];
				$org_title = $video_array['org_title'];
				$detailedString = $video.",".$trailer.",".$org_title.",".$primaryKeyValue;
			 }
			 return $detailedString;
         }
		 
//*************************************** END OF THE CODE ****************************************//

 


//********************************** FUNCTIONS FOR SHOW ANY LISTING WITH PAGINATION ****************************//

     function ListingPageCal($type,$tableName,$primaryKey,$searchString,$lmt,$char)
	   {
	      if($type == "video")
		   {
			    if($searchString == "")
				 {
				   if($char == "")
				     $video = "SELECT * FROM ".$tableName." WHERE status='u' ORDER BY ".$primaryKey." ASC ";
					 
				   if($char == "recent")
				     $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'";
					 
				   if($char == "populer")
				     $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'";
					 
				   if($char == "toprated")
				   	 $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'";	 
				 }  
				else
				  $video = $searchString;
				   
				$video_query = Query($video);
				$video_no = NumRows($video_query);
				$page = ceil($video_no/$lmt);
	       }
		  return $page; 
	   }

      function showListing($type,$tableName,$primaryKey,$ind,$lmt,$searchString,$char)
        {
		    if($type == "video") 
		     {
			    if($searchString == "")
				{
					
				   if($char == "")
				     $video = "SELECT * FROM ".$tableName." WHERE status='u' ORDER BY ".$primaryKey." ASC LIMIT $ind,$lmt";
					 
				   if($char == "recent")
				     $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'  LIMIT $ind,$lmt";
					 
				   if($char == "populer")
				     $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'  LIMIT $ind,$lmt";
					 
				   if($char == "toprated")
				   	 $video = "SELECT * FROM ".MOVIE." AS aa, ".VIDEODETAILS." AS bb WHERE aa.movieId=bb.movieID AND aa.status='u'  LIMIT $ind,$lmt";	 

					//$video = "SELECT * FROM ".$tableName." WHERE status='u' ORDER BY ".$primaryKey." ASC LIMIT $ind,$lmt";
				}
			   else
			        $video = $searchString;	
				    $video_query = Query($video);
				?>
					<table width="100%" border="0" cellspacing="1" cellpadding="1">
                      <tr>
					<?php
					$count = 0;
					while($video_array = FetchArray($video_query))
					 {
						$video_details = "SELECT * FROM ".VIDEODETAILS." WHERE movieID='".$video_array['movieId']."'";
						$video_details_query = Query($video_details);
						$video_details_array = FetchArray($video_details_query);
						$link = "movieDetails.php?movieID=".$video_details_array['movieID'];
					  ?>
					   <td> 
					   <div id="Sub1">
						   <div><a href="<?php echo $link; ?>"><img src="movieImageThumb/<?php echo $video_details_array['image']; ?>" height="80" border="0" /></a></div>
						   <div>&nbsp;</div>
						   <div><a href="<?php echo $link; ?>"><?php echo $video_array['org_title']; ?></a></div>
					   </div>
					   </td>
				  <?php
				       if($count >2)
					     {
						   $count = 0;
						   echo '</tr><tr>';
						 }
					 $count++;
				 }
				?>
				  
				  </tr>
				</table>			
      <?php	 
		  }	
		}

//************************************* END OF THE CODE ***************************************//



//************************************* FUNCTION TO SHOW THE STATIC PAGES ******************************//

      function ShowStaticPages($nameOfPage)
	   {
	      $name = "SELECT ".$nameOfPage." FROM ".PAGES;  
	      $name_query = Query($name);
		  $name_array = FetchArray($name_query);
		  echo $name_array[$nameOfPage];
	   }

//****************************************** END OF THE CODE *******************************************//



//****************************** FUNCTION FOR WISH LIST DETAILS **************************//

    function WishList($tablename)
     {
	 		$wish="SELECT * FROM ".$tablename." where 1" ;
			$query=Query($wish);
			?>
  		<table width="50%" border="0">
    	<tr>
      	<td colspan="17" align="center">WISH DETAILS</td>
  		</tr>
      	<tr height="5"></tr>
	
	<?php
	while($arry=FetchArray($query))
	{
	?>
    <tr>
      <td><?php echo $arry['0'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['1'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['2'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['3'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['4'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['5'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['6'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['7'];?></td>
      <td>&nbsp;</td>
      <td><?php echo $arry['8'];?></td>
    </tr>
  
<?php
        }?>
    </table>
		<?php
	 }
	 

//*********************************** END OF THE CODE ***********************************//




//************************************** FUNCTION FOR SHOWING CATEGORY *********************************//

       function ShowCategory($type,$nature)
        {
		   $option = "";
		   if($type == "movie" && $nature == "listBox")
		     {
			    $movie_category = "SELECT * FROM ".MOVIECATEGORY." ORDER BY categoryId ASC";
				$movie_category_query = Query($movie_category);
				$movie_category_no = NumRows($movie_category_query);

				if($movie_category_no > 0)
				 {
				   while($movie_category_array = FetchArray($movie_category_query))
				    {
				      $option.= '<option value="'.$movie_category_array['categoryId'].'">'.$movie_category_array['name'].'</option>';
					} 
				 }
				else
				 {
				    $option.= '<option value="">No Category Found</option>';
				 } 
			 }
		  
		  if($type == "movie" && $nature == "href") 
			 {
			    $movie_category = "SELECT * FROM ".MOVIECATEGORY." ORDER BY categoryId ASC";
				$movie_category_query = Query($movie_category);
				$movie_category_no = NumRows($movie_category_query);
			 
				if($movie_category_no > 0)
				 {			
				     while($movie_category_array = FetchArray($movie_category_query))
				    {
					  $option.= '<a href="video_listing.php?movieID='.$movie_category_array['categoryId'].'">'.$movie_category_array['name'].'</a><br>';
					} 
        		 }
			 } 
			 
		   if($type == "shop")
		     {
			    $shop = "SELECT * FROM ".SHOP." ORDER BY shopID ASC";
				$shop_query = Query($shop);
				$shop_no = NumRows($shop_query);

				if($shop_no > 0)
				 {
				   while($shop_array = FetchArray($shop_query))
				    {
				      $option.= '<option value="'.$shop_array['shopID'].'">'.$shop_array['shopName'].'</option>';
					} 
				 }
				else
				 {
				    $option.= '<option value="">No Shop Found</option>';
				 } 
			 }
		   if($type == "year")
		     {
				   for($year = 1960; $year<= 2050; $year++)
				    {
				      $option.= '<option value="'.$year.'">'.$year.'</option>';
					} 
			 }
			echo  $option;
		}

//***************************************** END OF THE CODE ********************************************//



//*********************************** FUNCTION FOR SHOWING SUBCATEGORY **************************//



//**************************************** END OF THE CODE *************************************//



//************************************ FUNCTION FOR CONTACT US **************************//

     function ContactUs($fromname,$details,$toemail,$fromemail)
	    {
		    $subject = "This is mail from Visitor";
			$body = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>
                       <td>Hi, <br>
                      <span><font face='Georgia, Times New Roman, Times, serif' size='3'>".$details."</font></span>
	                  </td>
                      </tr>
                    </table>";
			$headers  = "MIME-Version: 1.0 "."\r\n";
			$headers .= "Content-type: text/html; charset=iso-8859-1 "."\r\n";
			$headers .= "From: <".$fromemail.">"."\r\n";
			mail($toemail,$subject,$body,$headers);
       }

//************************************** END OF THE CODE **************************************//



//**************************************** FUNCTION FOR DISPLAY FAQS ***********************************//

          function ShowFAQ()
		   {
		      $faq = "SELECT * FROM ".FAQ." ORDER BY faqId ASC";   
		      $faq_query = Query($faq);
		      $faq_no = NumRows($faq_query);
			  
			  if($faq_no > 0)
			   {
			   ?>
			   <div id="faq">
			   <?php
			     while($faq_array = FetchArray($faq_query))
				  {
			   ?>
			      <div id="subfaq">
				  <div><font size="2" color="#FF0000" face="Bookman Old Style">Question : <?php PrintFunction($faq_array['head']); ?></font></div>
				  <div><font size="2" face="Bookman Old Style">Answer : <?php PrintFunction($faq_array['body']); ?></font></div>
				  <div>&nbsp;</div>
			      </div>
			   <?php
			      }
				  ?>
				 </div> 
			<?php	   
			   }
			  else
			   {  
			   ?>
			  <div><font size="2" color="#FF0000" face="Bookman Old Style">There Is No Faq In The Databse</font></div>
			  <?php
			   }
		   }

//****************************************** END OF THE CODE ********************************************//



//************************************ THE FUNCTION FOR CREATE IMAGE THUMB ******************************//

		function watermark($folderfrom,$folderto,$image,$ht)
		{
				$x=explode(".",$image);
				$ext=$x[1];
				switch($ext)
				{
					case "JPG":
					case "jpg":
					case "JPEG":
					case "jpeg":
						$ext="jpeg";
						break;
					case "GIF":
					case "gif":
						$ext="gif";
						break;
					case "PNG":
					case "png":
						$ext="png";
						break;
				}
				
		
				$img=$folderfrom.$image;
				
				switch($ext)
				{
					case "jpeg":
						$im=imagecreatefromjpeg($img);
						break;
					case "png":
						$im=imagecreatefrompng($img);
						break;
					case "gif":
						$im=imagecreatefromgif($img);
						break;
				}
				$imgx=imagesx($im);
				$imgy=imagesy($im);
				
				$watery=$ht;
				$waterx= intval(($watery/$imgy)*$imgx);
				
				$waterimage=imagecreatetruecolor($waterx,$watery);
				imagecopyresampled($waterimage,$im,0,0,0,0,$waterx,$watery,$imgx,$imgy);
				$im1=$folderto.$image;
				switch($ext)
				{
					case "jpeg":
						imagejpeg($waterimage,$im1);
						break;
					case "gif":
						imagegif($waterimage,$im1);
						break;
					case "png":
						imagepng($waterimage,$im1);
						break;
				}
				imagedestroy($waterimage);
		}

//*************************************** END OF THE CODE ***********************************************//


//*********************************** FUNCTION FOR GIVE COMMENT ON VIDEO *************************************//

		function  give_video_comment($userId,$movieID,$commentID,$comment)
		{
			$comment = "INSERT INTO ".MOVIECOMMENT." SET userId = '".$userId."', movieID = '".$movieID."', comment = '".$comment."' WHERE commentID='".$commentID."'";
			Query($comment);
		}

//**************************************** END OF THE CODE ************************************************//

//************************************* CODE FOR PAGINATION *********************************************//

function pagiing($lastpage,$page,$prev,$next,$lpm1)
{
	$pagination = "";
	if($lastpage > 1)
	{	
		if($page > 1) 
		{
			$pagination.= "<a href=\"?page=$prev\" class=\"blogCount\">Previous</a>";
		}
	   else
		{
			$pagination.= "<span class=\"blogPostby\">Previous</span>";	
		}
		   $pagination.= "&nbsp;<span class=\"blogPostby\">|</span>&nbsp;";

		if($page < $lastpage) 
		{
			$pagination.= "<a href=\"?page=$next\" class=\"blogCount\"><strong>Next</strong></a>";
		}
	   else
		{
			$pagination.= "<span class=\"blogPostby\">Next</span>";
		}
		$pagination.= "\n";		
	}
	return $pagination;
}




//***************************************** END OF THE CODE ********************************************//

//*********************************** FUNCTION FOR GIVE REPORT ON VIDEO *************************************//





//**************************************** END OF THE CODE ************************************************//



//*************************************** FUNCTION FOR DISPLAY ***************************************//

		function display()
		{
		$select_reg_form="SELECT * FROM user";
		$mysql_query_reg_form=mysql_query($select_reg_form)or die(mysql_error());
		?><div><?php
		while($q=mysql_fetch_array($mysql_query_reg_form))
		{
		?><div><?php
		echo $q['username'];
		echo $q['password'];
		echo $q['firstName'];
		echo $q['lastName'];
		echo $q['email'];
		echo $q['address'];
		echo $q['phone'];
		echo $q['fax'];
		echo $q['city'];
		echo $q['zip'];
		echo $q['date'];
		echo $q['status'];
		?></div><?php
		}?>
		</div><?php
		}

//*********************************** END OF THE CODE *********************************************//

//********************************* THE FUNCTIONS FOR TEMPORARY WORKS ******************************//

			function check_image_file($imgfile)
			{
				$extn=explode(".",$imgfile);
				$number=count($extn);
				$imgextn=strtolower($extn[$number-1]);
				
				if($imgextn=='jpeg' || $imgextn=='jpg' || $imgextn=='gif' || $imgextn=='png' || $imgextn=='bmp')
				{
				return true;
				}
				else
				{
				return false;
				}
			
			}
			
			
			function fileupload($uploadname,$imgname,$dirname)
			{
				if(is_uploaded_file($uploadname))
				{
					if(!is_dir($dirname))
					{
					umask(0);
					mkdir("$dirname",0777);
					}
					if(move_uploaded_file($uploadname,"$dirname/".$imgname))
					{
					return $uploadname;
					//echo $filename;
					}
					else
					{
					return 0;
					}
				}
			}

//**************************** END OF THE CODE ***************************************//

?>